<template>
	<view class="inspect-main">
		<!-- inspect一级巡查 -->
		<view v-for="(inspect, index) in inspects" :key="index">
			<view class="inspect-main-container" :class="{'inspect-main-container-open': inspect.open}" @click.native="itemShow(index)">
				<view class="inspect-main-container-title">
                    {{ inspect.typeName }}
                    <span>({{ inspect.children.length }})</span>
                </view>
				<!-- inspect.checkResult(0,已巡查正常，1已巡查异常) -->
				<view v-if="inspect.checkResult" class="inspect-main-container-tip" :class="{'inspect-main-container-tip-exception': inspect.checkResult == '1' }">
					{{ inspect.checkResult == '0' ? '正常' : '异常' }}
				</view>
				<image class="inspect-main-container-icon" :src="inspect.open ? '/static/imgs/icon/arrow_up.png' : '/static/imgs/icon/arrow_down.png'"></image>
			</view>
			<view v-if="inspect.open" class="inspect-main-container-content">
				<!-- inpectItem二级巡查 图片保存在辞职，bizType使用二级巡查id，fileGroup：0巡查；1复查，目前只有复查有附件 -->
				<view v-for="(inpectItem, iIndex) in inspect.children" :key="iIndex">
					<view class="inspect-main-container inspect-main-container-open" @click.native="itemShow(index, iIndex)">
						<view class="inspect-main-container-title">{{ inpectItem.typeName }}</view>
						<!-- inpectItem.checkResultId normal表示正常 -->
						<view v-if="inpectItem.checkResultId" class="inspect-main-container-tip" :class="{'inspect-main-container-tip-exception': inpectItem.checkResultId != 'normal' }">
							{{ inpectItem.checkResultId == 'normal' ? '正常' : '异常' }}
						</view>
						<image class="inspect-main-container-icon" :src="inpectItem.open ? '/static/imgs/icon/arrow_up.png' : '/static/imgs/icon/arrow_down.png'"></image>
					</view>
					<view v-if="inpectItem.open">
						<view class="inspect-check-item">
							<!-- inpectItem.checkResultId normal表示正常 -->
							<view class="inspect-check-item-content" :class="{'inspect-check-item-content-select': inpectItem.checkResultId == 'normal' }"
                                @click.native="checkItemClick(index, iIndex, -1, normalCheck)">
								{{ normalCheck.typeName }}
							</view>
							<!-- inpectItem.checkResultId normal表示正常 -->
							<view v-for="(child, cIndex) in inpectItem.children" :key="cIndex" class="inspect-check-item-content" :class="{'inspect-check-item-content-select': inpectItem.checkResultId == child.id }"
                                @click.native="checkItemClick(index, iIndex, cIndex, child)">
								{{ child.typeName }}
							</view>
						</view>
                        
                        <!-- 2.1需求巡查底部 add by ray on 2021/02/29 -->
                        <view v-if="inspectType == 0 && inpectItem.checkResultId != 'normal' && !showInspect">
                            <view class="inspect-main-container inspect-main-container-open-child">上报方式</view>
                            <view class="inspect-check-item">
                            	<view v-for="(button, btnIndex) in inspectButtons" 
                                    :key="btnIndex" 
                                    class="inspect-check-item-content" 
                                    :class="{'inspect-check-item-content-select': inpectItem.reportWay == button.value }"
                                    @click.native="inspectButtonClick(index, iIndex, inpectItem, button)">
                            		{{ button.name }}
                            	</view>
                            </view>
                            <view class="inspect-main-container inspect-main-container-open-child"
                                v-if="inpectItem.reportWay == '1'"
                            >
                                现场照片（1张整改前和1张整改后）：
                            </view>
                            <view class="attachment-container"
                                v-if="inpectItem.reportWay == '0' || inpectItem.reportWay == '1' || inpectItem.reportWay == '3'"
                            >
                                <view class="attachment">
                                    <view class="attribute">
                                        <view class="asterisk">*</view>
                                        <view>
                                            {{
                                                inpectItem.reportWay == '1'
                                                    ? "整改前"
                                                    : "现场照片（1张清晰照片）"
                                            }}
                                        </view>
                                    </view>
                                    <view class="attachment-area">
                                        <view class="attachment-area-item" v-for="(item, aIndex) in inpectItem.eventImages" :key="aIndex">
                                            <!-- <image class="image-style" :src="item.src" @click="previewImage(inpectItem.eventImages, aIndex)">
                                            </image> -->
                                            <img class="image-style" :src="item.src"
                                                @click="previewImage(inpectItem.eventImages, aIndex)"/>
                                            <image v-if="!showInspect" class="image-delete" :src="'/static/imgs/icon/clo.png'"
                                                @click="deleteFile(index, iIndex, aIndex, item, 'eventImages')">
                                            </image>
                                        </view>
                                        <!-- 增加巡查纳入复查附件逻辑inpectItem.reportWay == '3' -->
                                        <ray-pick-files v-if="!showInspect && (!inpectItem.eventImages || inpectItem.eventImages.length < 1)" 
                                            :menuType="'0'"
                                            :bizType="inpectItem.reportWay == '3' ? inpectItem.id : 'task'"
                                            :fileGroup="inpectItem.reportWay == '3' ? 'czwxc' : '0'"
                                            :poses="[index, iIndex]"
                                            @fileEventPickedChange="fileEventPickedChange"
                                            :filePicked="'fileEventPickedChange'">
                                        </ray-pick-files>
                                    </view>
                                </view>
                                <view class="attachment"
                                    v-if="inpectItem.reportWay == '1'"
                                >
                                    <view class="attribute">
                                        <view class="asterisk">*</view>
                                        <view>整改后</view>
                                    </view>
                                    <view class="attachment-area">
                                        <view class="attachment-area-item" v-for="(item, aIndex) in inpectItem.eventRectifyImages" :key="aIndex">
                                            <!-- <image class="image-style" :src="item.src" @click="previewImage(inpectItem.eventRectifyImages, aIndex)">
                                            </image> -->
                                            <img class="image-style" :src="item.src"
                                                @click="previewImage(inpectItem.eventRectifyImages, aIndex)"/>
                                            <image v-if="!showInspect" class="image-delete" :src="'/static/imgs/icon/clo.png'"
                                                @click="deleteFile(index, iIndex, aIndex, item, 'eventRectifyImages')">
                                            </image>
                                        </view>
                                        <ray-pick-files v-if="!showInspect && (!inpectItem.eventRectifyImages || inpectItem.eventRectifyImages.length < 1)" 
                                            :menuType="'0'"
                                            :bizType="'task'"
                                            :fileGroup="'jcjb_after'"
                                            :poses="[index, iIndex]"
                                            @fileEventRectifyPickedChange="fileEventRectifyPickedChange"
                                            :filePicked="'fileEventRectifyPickedChange'">
                                        </ray-pick-files>
                                    </view>
                                </view>
                            </view>
                            
                            <textarea class="text-area-s"
                                v-if="inpectItem.reportWay == '0' || inpectItem.reportWay == '1'"
                                v-model="inpectItem.remark"
                                :placeholder="'备注'" 
                                maxlength="500"
                            >
                            </textarea>
                        </view>
                        
                        <!-- 复查底部 -->
						<view v-if="inspectType == 1">
							<view class="inspect-main-container inspect-main-container-open-child">现场整改</view>
							<view class="inspect-check-item">
								<!-- inpectItem.isReviewChange复查整改 -->
								<view v-for="(rectify, rIndex) in rectifies" :key="rIndex" class="inspect-check-item-content" :class="{'inspect-check-item-content-select': inpectItem.isReviewChange == rectify.value }"
                                    @click.native="rectifyCheck(index, iIndex, inpectItem, rectify)">
									{{ rectify.name }}
								</view>
							</view>
							<view class="attachment">
								<!-- <view class="attribute">
                                    <view class="asterisk">*</view>
                                    <view>现场图片</view>
                                </view> -->
								<view class="attachment-area">
									<view class="attachment-area-item" v-for="(item, aIndex) in inpectItem.imageList" :key="aIndex">
										<!-- <image class="image-style" :src="item.src" @click="previewImage(inpectItem.imageList, aIndex)">
										</image> -->
                                        <img class="image-style" :src="item.src"
                                            @click="previewImage(inpectItem.imageList, aIndex)"/>
										<image v-if="!showInspect" class="image-delete" :src="'/static/imgs/icon/clo.png'"
                                            @click="deleteFile(index, iIndex, aIndex, item, 'imageList')">
										</image>
									</view>
									<!-- <view class="attachment-area-item" v-for="(item, index) in inpectItem.fileList"
                                        :v-bind:key="index" :key="index">
                                        <image class="image-style" :src="'/static/imgs/icon/clo.png'">
                                        </image>
                                        <image class="image-delete" 
                                            src="/static/imgs/icon/clo.png"
                                            @click="deleteFile(1, item)">
                                        </image>
                                    </view> -->
                                    <!-- fileGroup原来为1，现修改复查时为0，修复服务端上报事件无附件问题 modify by ray on 2021/01/11 -->
									<ray-pick-files v-if="!showInspect && (!inpectItem.imageList || inpectItem.imageList.length < 2)" 
                                        :menuType="'0'"
                                        :bizType="inpectItem.id"
                                        :fileGroup="'0'"
                                        :poses="[index, iIndex]"
                                        @filePickedChange="filePickedChange"
                                        :filePicked="'filePickedChange'">
									</ray-pick-files>
									<!-- <view v-if="imagePaths[1].length < 4 && editEnable"
                                        class="attachment-area-item attachment-area-item-center"
                                        @click="chooseImage(1)"
                                        >
                                        <image class="image-add" :src="'/static/imgs/icon/clo.png'">
                                        </image>
                                    </view> -->
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<uni-popup ref="popupCheck" type="bottom" :maskClick="true" @change="popChange">
			<view class="inspect-pop-menu-main">
				<view v-for="(menu, index) in menus" :key="index" @click.native="menuCheckClick(menu)" class="inspect-pop-menu-main-menu"
                    :class="{'inspect-pop-menu-main-menu-bottom': index < (menus.length - 1)}">
					{{ menu.name }}
				</view>

			</view>
			<view class="inspect-pop-menu-cancel" @click.native="cancelPop()">
				取消
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import Vue from 'vue';
	import {
		RayPickFiles
	} from '@/components/ray-pick-files/ray-pick-files.vue';
	import {
		UniPopup
	} from '@/components/uni-popup/uni-popup.vue';
	import {
		createUUID
	} from '@/utils/createUUID';

	export default {
		name: 'ray-inspect',
		components: {
			RayPickFiles,
			UniPopup
		},
		props: {

			/**
			 * 显示检查json，复查和显示时必填
			 */
			inspectJson: {
				type: String,
				default () {
					return '';
				}
			},
			/**
			 * 显示时禁用，默认时非显示
			 */
			showInspect: {
				type: Boolean,
				default: false
			},

			/**
			 * 回调函数方法名，默认为inspectSelected
			 */
			inspectSelected: {
				type: String,
				default () {
					return 'inspectSelected';
				}
			},

			/**
			 * 巡查项类型
			 */
			inspectItemType: {
				type: [String, Number],
				default () {
					return '';
				}
			},

			/**
			 * 巡查类型
			 * 0巡查，1复查
			 */
			inspectType: {
				type: [String, Number],
				default () {
					return 0;
				}
			},
		},
		components: {},
		data() {
			return {
				// 巡查点击菜单
				menus: [
                    {
						name: "待复查",
						value: "1001"
					},
					{
						name: "事件上报",
						value: "1002"
					},
				],
                /**
                 * 巡查点击菜单
                 * 一般事件 0
                   即采即办 1
                   紧急事件 2
                   纳入复查 3
                   正常 ：不用传值 空值
                 */
                inspectButtons: [
                    {
                    	name: "即采即办",
                    	value: "1"
                    },
                    {
                		name: "纳入复查",
                		value: "3"
                	},
                	{
                		name: "事件上报",
                		value: "0"
                	},
                ],
				// 原始数据巡查项
				originInpects: [],
				// 处理后的巡查项，可以是巡查，也可以是复查 checkResult(0,已巡查正常，1已巡查异常) checkResultId
				inspects: [],

				// 正常选项
				normalCheck: {
					id: "normal",
					typeName: "正常",
				},

				// 复查
				rectifies: [{
						name: "已整改",
						value: "1",
					},
					{
						name: "未整改",
						value: "0",
					},
				],
				// 点击选中的巡查内容，巡查时使用；保存三级项
				chooses: [],

			};
		},
		onLoad() {
        },
        watch: {
        	inspectItemType (newVal, oldVal) {
                let __this = this;
                if (newVal != oldVal) {
                    __this.init();
                }
            },
            inspectJson (newVal, oldVal) {
                let __this = this;
                if (newVal != oldVal) {
                    __this.init();
                }
            }
        },
		created() {
			this.init();
		},
		onShow() {
        },
		methods: {
            
            init () {
                let __this = this;
                __this.inspects = [];
                if (!this.inspectItemType) {
                	// uni.showToast({
                	// 	title: '请设置巡查项类别',
                	// 	icon: 'none'
                	// });
                    return;
                } else {
                	this.originInpects = this.$store.state.inspectItems;
                
                	let showObj = "";
                	if (this.inspectJson) {
                		showObj = JSON.parse(this.inspectJson);
                	}
                	// console.log(showObj);
                	if (this.inspectType && this.inspectType == "1") {
                		// 复查内容
                		if (!this.inspectJson) {
                			// uni.showToast({
                			// 	title: '请设置复查内容',
                			// 	icon: 'none'
                			// });
                			return;
                		}
                	}
                	this.originInpects = this.originInpects.filter(function(item) {
                		return item.id == __this.inspectItemType;
                	});
                	console.log(this.originInpects);
                	if (this.originInpects.length > 0) {
                		if (!this.inspectJson) {
                			// debugger
                			let insPectClickData = this.$store.state.insPectClickData;
                
                            if (this.insPectClickData && this.insPectClickData.length > 0) {
                                this.inspects = JSON.parse(JSON.stringify(insPectClickData));
                                return;
                            }
                
                			this.inspects = JSON.parse(JSON.stringify(this.originInpects[0].children));
                
                			// 默认选中正常
                			let list = this.inspects;
                			list.forEach((item, index) => {
                				if (!!item.children && item.children.length > 0) {
                					let children = item.children
                					children.forEach((item1, iIndex) => {
                                        this.checkItemClick(index, iIndex, -1, {
                                            id: "normal",
                                            typeName: "正常",
                                        });
                						// if (insPectClickData.length > 0) {
                						// 	let insPect = {};
                						// 	for (let i of insPectClickData) {
                						// 		if (i.inspectIndex == index && i.inspectItemIndex == iIndex) {
                						// 			console.log(i.inspectIndex, i.inspectItemIndex, i.checkIndex, i.checkItem)
                						// 			insPect = i;
                						// 			break;
                						// 		}
                						// 	}
                						// 	if (Object.keys(insPect).length > 0) {
                						// 		this.checkItemClick(insPect.inspectIndex, insPect.inspectItemIndex, insPect.checkIndex, insPect.checkItem,
                						// 			true);
                						// 		this.menuCheckClick({
                						// 			name: "待复查",
                						// 			value: "1001"
                						// 		}, true);
                
                						// 	} else {
                						// 		this.checkItemClick(index, iIndex, -1, {
                						// 			id: "normal",
                						// 			typeName: "正常",
                						// 		});
                						// 	}
                						// } else {
                						// 	// 一个个设置正常
                						// 	this.checkItemClick(index, iIndex, -1, {
                						// 		id: "normal",
                						// 		typeName: "正常",
                						// 	});
                						// }
                					});
                				}
                			});
                
                		} else {
                			let dics = JSON.parse(JSON.stringify(this.originInpects[0].children));
                			dics.forEach((parentDic) => {
                				let abs = showObj.filter((showFilter) => {
                					return showFilter.key == parentDic.id;
                                });
                				// console.log(JSON.stringify(parentDic));
                				// console.log(JSON.stringify(abs[0]));
                				let children = [];
                				if (abs.length > 0) {
                					abs[0].abnormals.forEach((abnormal) => {
                						for (let i = 0; i < parentDic.children.length; i++) {
                							let childDic = parentDic.children[i];
                							if (childDic.id == abnormal.dangerTypeCode) {
                								// 隐患，并且未主动上报事件
                								if (abnormal.isDanger == "1" && abnormal.isReportEvent != "1") {
                									parentDic.checkResult = "1";
                                                    childDic.checkResultId = abnormal.itemDetailsId;
                                                    // 服务端要新增复查任务id add by ray on 2021/01/08
                                                    childDic.reviewCheckId = abnormal.reviewCheckId;
                									children.push(childDic);
                								}
                                                else if (this.inspectType != "1") {
                                                    // 如果要显示正常的巡查项，则执行此处
                                                    childDic.checkResultId = "normal";
                                                    children.push(childDic);
                                                }
                
                								break;
                							}
                						}
                					});
                					if (children.length > 0) {
                						parentDic.children = children;
                						this.inspects.push(parentDic);
                					}
                				}
                			});
                
                		}
                	}
                }
            },

			/**
			 * 巡查项展开
			 * @param {Object} inspectIndex 一级目录位置
			 * @param {Object} inspectItemIndex 二级目录位置
			 */
			itemShow(inspectIndex, inspectItemIndex) {
				console.log(inspectIndex, inspectItemIndex);
				if (inspectItemIndex != undefined) {
					// 二级目录展开
					let open = "";
					if ((this.inspects[inspectIndex].children)[inspectItemIndex].open) {
						open = !(this.inspects[inspectIndex].children)[inspectItemIndex].open;
					} else {
						open = true;
					}
					Vue.set((this.inspects[inspectIndex].children)[inspectItemIndex], "open", open);
				} else {
					// 一级目录展开
					let open = "";
					if (this.inspects[inspectIndex].open) {
						open = !this.inspects[inspectIndex].open;
					} else {
						open = true;
					}
					Vue.set(this.inspects[inspectIndex], "open", open);
				}
			},

			cancelPop() {
				this.chooses = [];
				this.$refs.popupCheck.close();
			},

			popChange(val) {
				if (!val.show) {
					this.chooses = [];
					console.log(this.chooses);
				}
            },

            /**
             * 巡查项插入值
             * add by ray on 2021/01/21
             */
            insertParamsToInspectItem (positions, key, value) {
                let __this = this;
                let arr = JSON.parse(positions);
                console.log(arr.length);
                console.log(key);
                console.log(value);
                if (arr && arr.length > 0) {
                    if (arr.length == 1) {
                        if (key && value) {
                            Vue.set(__this.inspects[arr[0]], key, value);
                        }
                    } else if (arr.length == 2) {
                        if (key && value) {
                            Vue.set((__this.inspects[arr[0]].children)[arr[1]], key, value);
                        }
                    } else if (arr.length == 3) {
                        if (key && value) {
                            Vue.set(((__this.inspects[arr[0]].children)[arr[1]].children)[arr[2]],
                                key, value);
                        }
                    }
                }
            },
            
            /**
             * 2.1巡查事件功能
             * @param {Object} index
             * @param {Object} iIndex
             * @param {Object} inpectItem
             * @param {Object} button
             */
            inspectButtonClick(index, iIndex, inpectItem, button) {
        		let __this = this;
        		console.log(button.value);
                /**
                    一般事件 0
                    即采即办 1
                    紧急事件 2
                    纳入复查 3
                    正常 ：不用传值，空值
                 */
                Vue.set((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]],
                	"reportWay", button.value);
                Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]],
                	"reportWay", button.value);
        		switch (button.value) {
        			case "3":
        				Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]],
        					"isReportEvent", "0");
        				// Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]], 
        				//     "eventId", "");
                        Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]],
                            "eventJSON", "");
        				break;
        			case "0":
                    case "1":
                        try {
                            app.setting.set(
                                {
                                    key: "rayInspectChooses",
                                    value: __this.chooses
                                }
                            );
                        } catch (e) {
                            console.log(e);
                        }
                        let businessId = ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].eventBusinessTypeId;
                        let kindId = ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].eventKindId;
                        let typeId = ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].eventTypeId;
                        if (!businessId && !kindId && !typeId) {
                            uni.showToast({
                                title: '请联系管理员配置事件类型',
                                icon: 'none'
                            });
                            Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]],
                                "reportWay", "");
                            return;
                        }
                        // 事件上报 isReportEvent = 1
                        Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]],
                            "isReportEvent", "1");
            
                        // 拼接事件类型
                        // let eventId = createUUID();
                        // Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]], 
                        //     "eventId", eventId);
                        let eventJson = {
                            // eventId: eventId,
                            businessId: businessId,
                            businessName: ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].eventBusinessType,
                            kindId: kindId,
                            kindName: ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].eventKind,
                            typeId: typeId,
                            typeName: ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].eventType,
                            content: ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].typeName,
                        };
            
                        // // 暂时跳转到事件采集
                        // this.bindChange(eventJson);
                        // 2.1需求，不跳转事件
                        Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]],
                            "eventJson", eventJson);
                        __this.$store.commit('updateInsPectClickData', __this.inspects);
                        break;
                }
        	},

			menuCheckClick(item, isFromLocal) {
				let __this = this;
				console.log(item.value);
				switch (item.value) {
					case "1001":
						Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]],
							"isReportEvent", "0");
                        Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]], 
                            "eventId", "");
                        /**
                         * 服务端要求增加reportWay
                            一般事件 0
                            即采即办 1
                            紧急事件 2
                            纳入复查 3
                            正常 ：不用传值 空值
                         * add by ray on 2021/03/10
                         */
                        Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]],
                        	"reportWay", "3");
						break;
					case "1002":
                        // 记录巡查位置，事件采集即采即办时需修改内容 add by ray on 2021/01/21
                        try {
                            app.setting.set(
                                {
                                    key: "rayInspectChooses",
                                    value: __this.chooses
                                }
                            );
                        } catch (e) {
                            console.log(e);
                        }
                        let businessId = ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].eventBusinessTypeId;
                        let kindId = ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].eventKindId;
                        let typeId = ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].eventTypeId;
                        if (!businessId && !kindId && !typeId) {
                            uni.showToast({
                                title: '请联系管理员配置事件类型',
                                icon: 'none'
                            });
                            return;
                        }
						// 事件上报 isReportEvent = 1
						Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]],
							"isReportEvent", "1");
                        // 可能需要保存巡查项保存当前巡查数据inspects

						// 拼接事件类型
						let eventId = createUUID();
						Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]], 
                            "eventId", eventId);
						// let eventJson = {
						// 	eventId: eventId,
						// 	businessId: __this.inspects[__this.chooses[0]].id,
						// 	businessName: __this.inspects[__this.chooses[0]].typeName,
						// 	kindId: (__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].id,
						// 	kindName: (__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].typeName,
						// 	typeId: ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].eventTypeId,
						// 	typeName: ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].typeName,
						// 	content: ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].typeName,
                        // };
                        let eventJson = {
							eventId: eventId,
							businessId: businessId,
							businessName: ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].eventBusinessType,
							kindId: kindId,
							kindName: ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].eventKind,
							typeId: typeId,
							typeName: ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].eventType,
							content: ((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]].typeName,
						};

						// // 判断巡查状态
						// uni.navigateTo({
						// 	url: '../../pages/event-report/event-report'
						// });

						// 暂时跳转到事件采集
						this.bindChange(eventJson);
						break;
                }

                // 加入待复查
                // 该逻辑从switch前移动到之后
                // 判断事件是否可以上报，服务端需要判断是否可以正常上报 modify by ray on 2021/01/18
				if (__this.inspectType == "0") {
					// 异常巡查
					Vue.set(__this.inspects[__this.chooses[0]], "checkResult", "1");
					// 单选异常内容
					Vue.set((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]], 
                        "checkResultId", (((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]]).id);
					Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]], 
                        "isCheck", "1");
				}

                this.cancelPop();
    //             console.log(isFromLocal);
				// if (!isFromLocal || isFromLocal == false) {
				// 	this.cancelPop();
				// }

			},

			/**
			 * 巡查选项点击
			 * @param {Object} inspectIndex 一级目录位置
			 * @param {Object} inspectItemIndex 二级目录位置
			 * @param {Object} checkItem 选中内容
			 */
			checkItemClick(inspectIndex, inspectItemIndex, checkIndex, checkItem, isFromLocal) {
				if (this.showInspect || this.inspectType == "1") {
					return;
				}
				let __this = this;
				if (checkItem && checkItem.id == "normal") {
					// 选中正常
					Vue.set((__this.inspects[inspectIndex].children)[inspectItemIndex], "checkResultId", checkItem.id);

					let pa = (__this.inspects[inspectIndex].children).filter((item) => {
						return (item.checkResultId && item.checkResultId != checkItem.id);
					});

					Vue.set(__this.inspects[inspectIndex], "checkResult", pa.length > 0 ? "1" : "0");

					if (this.inspectType == "0") {
						// 巡查正常

					} else {
						// 复查异常

					}
				} else {

					// debugger
					__this.chooses = [inspectIndex, inspectItemIndex, checkIndex];
					// 选中异常
					if (__this.inspectType == "0") {
						// 异常巡查
                        
                        // 2.1需求，不通过弹框选取
                        // __this.$refs.popupCheck.open();
                        Vue.set(__this.inspects[__this.chooses[0]], "checkResult", "1");
                        // 单选异常内容
                        Vue.set((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]], 
                            "checkResultId", (((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]]).id);
                        Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]], 
                            "isCheck", "1");
                        
						// if (!isFromLocal || isFromLocal == false) {
						// 	//将选中的数据缓存
						// 	let item = {
						// 		inspectIndex: inspectIndex,
						// 		inspectItemIndex: inspectItemIndex,
						// 		checkIndex: checkIndex,
						// 		checkItem: checkItem
						// 	}
						// 	let insPectClickData = this.$store.state.insPectClickData;
						// 	if (insPectClickData.length == 0) {
						// 		insPectClickData.push(item)
						// 		this.$store.commit('updateInsPectClickData', insPectClickData)
						// 	} else {
						// 		let isIn = false;
						// 		for (let i of insPectClickData) {
						// 			if (i.inspectIndex == inspectIndex && i.inspectItemIndex == inspectItemIndex &&
						// 				i.checkIndex == checkIndex && i.checkItem.id == checkItem.id) {
						// 				isIn = true
						// 				break;
						// 			}
						// 		}
						// 		if (isIn == false) {
						// 			//之前不存在
						// 			insPectClickData.push(item)
						// 			this.$store.commit('updateInsPectClickData', insPectClickData)
						// 		}

						// 	}
						// 	__this.$refs.popupCheck.open();
						// } else {}

					} else {
						// 异常复查
						Vue.set(__this.inspects[__this.chooses[0]], "checkResult", "1");
						// 单选异常内容
						Vue.set((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]], 
                            "checkResultId", (((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]]).id);
						Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]], 
                            "isCheck", "1");
					}
				}
			},

			/**
			 * 复查整改选择
			 * @param {Object} inspectIndex 一级目录位置
			 * @param {Object} inspectItemIndex 二级目录位置
			 * @param {Object} inspectItem
			 */
			rectifyCheck(inspectIndex, inspectItemIndex, inspectItem, recify) {
				let __this = this;
				console.log(recify);
				console.log(__this.inspects[inspectIndex]);
				console.log((__this.inspects[inspectIndex].children)[inspectItemIndex]);
				Vue.set((__this.inspects[inspectIndex].children)[inspectItemIndex], "isReviewChange", recify.value);
			},

			/**
			 * @description:value 改变时触发 change 事件
			 * @author ray
			 */
			bindChange(data) {
                this.$store.commit('updateInsPectClickData', this.inspects);
				this.$emit(this.inspectSelected, data);
			},
            
            /**
             * 事件附件选取回调
             * @param {Object} val
             */
            fileEventPickedChange(val) {
                let __this = this;
                console.log(val);
            	let files = (__this.inspects[val.poses[0]].children)[val.poses[1]].eventImages;
            	if (!files) {
            		files = [];
            	}
            	files.push(val);
            
            	Vue.set((__this.inspects[val.poses[0]].children)[val.poses[1]], "eventImages", files);
            },
            
            /**
             * 事件-处置后附件选取回调
             * @param {Object} val
             */
            fileEventRectifyPickedChange(val) {
                let __this = this;
                console.log(val);
            	let files = (__this.inspects[val.poses[0]].children)[val.poses[1]].eventRectifyImages;
            	if (!files) {
            		files = [];
            	}
            	files.push(val);
            
            	Vue.set((__this.inspects[val.poses[0]].children)[val.poses[1]], "eventRectifyImages", files);
            },

			/**
			 * 附件选取回调
			 * @param {Object} val
			 */
			filePickedChange(val) {
                let __this = this;
                console.log(val);
				let files = (__this.inspects[val.poses[0]].children)[val.poses[1]].imageList;
				if (!files) {
					files = [];
				}
				files.push(val);

				Vue.set((__this.inspects[val.poses[0]].children)[val.poses[1]], "imageList", files);
			},

			/**
			 * 删除附件
			 * @param {Object} index 1级巡查项pos
			 * @param {Object} iIndex 2级巡查项pos
			 * @param {Object} aIndex 附件pos
			 * @param {Object} item 附件内容
			 * @param {Object} key 附件所属键值key
			 */
			deleteFile(index, iIndex, aIndex, item, key) {
				let _this = this;
				uni.showModal({
					title: '提示',
					content: '确定要删除该文件吗',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							// fileType, image/auido/video
							if (item.fileType == "image") {
                                let images = ((_this.inspects[index].children)[iIndex])[key];
								images.some((t, i) => {
									if (t.src == item.src) {
										images.splice(i, 1);
										// 在数组的some方法中，如果return true，就会立即终止这个数组的后续循环,所以相比较foreach，如果想要终止循环，那么建议使用some
										return true;
									}
								});
                                Vue.set((_this.inspects[index].children)[iIndex], key, images);
							}

							// let deleteParams = [ item.systemid ];
							// _this.$api.attachmentDel(JSON.stringify([item.systemid])).then(
							//     resp => {
							//         if (resp.state){
							//             uni.showToast({
							//             	title: '删除成功！',
							//             	icon: 'none'
							//             });
							//             // _this.imagePaths[pos] = (_this.imagePaths[pos]).filter(t => t.systemid != item.systemid);
							//             _this.imagePaths[pos].some((t, i) => {
							//             	if (t.systemid == item.systemid ){
							//             		_this.imagePaths[pos].splice(i, 1);
							//             		// 在数组的some方法中，如果return true，就会立即终止这个数组的后续循环,所以相比较foreach，如果想要终止循环，那么建议使用some
							//             		return true;
							//                 }
							//             });
							//         }
							//     }
							// );
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},

			/**
			 * 图标片预览
			 */
			previewImage(arrayList, index) {
                return;
				let paths = [];
				console.log(arrayList, index);
				arrayList.forEach((item) => {
					paths.push(item.src);
				});
				// 预览图片
				uni.previewImage({
					urls: paths,
					current: index,
					// 图片指示器样式，可取值："default" - 底部圆点指示器； "number" - 顶部数字指示器； "none" - 不显示指示器。
					indicator: 'default',
				});
			},
		}
	};
</script>
<style lang="scss" scoped>
	.inspect-main {

		.inspect-pop-menu-main {
			margin: 15rpx 30rpx;
			background: #ffffff;
			border-radius: 15rpx;
			padding: 20rpx;

			.inspect-pop-menu-main-menu {
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 30rpx;
				color: #666666;
				font-size: 34rpx;
			}

			.inspect-pop-menu-main-menu-bottom {
				border-bottom: 1rpx solid #f6f6f6;
			}
		}

		.inspect-pop-menu-cancel {
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 30rpx;
			color: #666666;
			font-size: 34rpx;
			margin: 15rpx 30rpx;
			background: #ffffff;
			border-radius: 15rpx;
		}

		.inspect-main-container {
			padding: 20rpx;
			display: flex;
			width: 100%;
			background-color: #ffffff;
			border-bottom: 1rpx solid #f5f5f5;
			align-items: center;

			.inspect-main-container-title {
				font-size: 32rpx;
				color: #333333;
				flex: 1;
			}

			.inspect-main-container-tip {
				font-size: 28rpx;
				color: #666666;
			}

			.inspect-main-container-tip-exception {
				font-size: 28rpx;
				color: #FF0000;
			}

			.inspect-main-container-icon {
				height: 48rpx;
				width: 48rpx;
				margin-left: 5rpx;
			}
		}

		.inspect-main-container-open {
			background-color: #f6f6f6;
		}

		.inspect-main-container-open-child {
			background-color: #f6f6f6;
			border-bottom: 0rpx solid #e5e5e5;
		}

		.inspect-main-container-content {
			padding: 0 20rpx 0 40rpx;
			width: 100%;
			background-color: #f6f6f6;
		}

		.inspect-check-item {
			padding: 10rpx;
			display: flex;
			// justify-content: center;
			flex-wrap: wrap;
			flex-direction: row;
		}

		.inspect-check-item-content {
			padding: 10rpx 20rpx;
			// border: 1rpx solid #C0C0C0;
			background-color: #DCDCDC;
			border-radius: 15rpx;
			margin: 10rpx;
			display: flex;
			font-size: 26rpx;
			color: #666666;
			align-items: center;
		}

		.inspect-check-item-content-select {
			background-color: #6084e9;
			color: #ffffff;
		}
        
        .text-area-s {
            background-color: #ffffff;
            border-radius: 10rpx;
            flex: 1;
            width: 90%;
            padding: 15rpx;
            margin: 20rpx;
            height: 160rpx;
        }
        
        .attachment-container {
            display: flex;
        }

		.attachment {
			padding: 20rpx 10rpx;
			border-bottom: 1rpx solid #f5f5f5;
			margin: 0 10rpx;
            flex: 1;

			.attribute {
				display: flex;

				.asterisk {
					color: #ff0000;
					padding: 0 5rpx;
					width: 30rpx;
				}
			}

			.attachment-area {
				margin-top: 10rpx;
				// padding: 10rpx;
				// border: 0.1rpx solid #cdcdcd;
				border-radius: 5rpx;
				display: flex;
				flex-wrap: wrap;
				flex-direction: row;
				justify-content: flex-start;

				.attachment-area-item-center {
					justify-content: center;
					align-items: center;
					background-color: #f5f5f5;
				}

				.attachment-area-item {
					width: 130rpx;
					height: 130rpx;
					// padding-top: 20rpx;
					// padding-bottom: 20rpx;
					// padding-left: 10rpx;
					// padding-right: 10rpx;
					padding: 5rpx;
					// background-color: #f5f5f5;
					border-radius: 5rpx;
					// border: 0.1rpx solid #cdcdcd;
					margin: 15rpx;
					// align-items: center;
					display: flex;
					// justify-content: center;
					position: relative;

					.image-style {
						width: 130rpx;
						height: 130rpx;
					}

					.image-add {
						width: 48rpx;
						height: 48rpx;
					}

					.image-delete {
						position: absolute;
						z-index: 10;
						font-size: 18px;
						color: #ee0a24;
						width: 48rpx;
						height: 48rpx;
						margin-left: 90rpx;
						margin-top: -20rpx;
					}

					.attachment-area-item-value {
						font-size: 26rpx;
						color: #666666;
						text-align: start;
					}
				}
			}
		}
	}
</style>
